package com.sright.bcard.enterprise.web.controller;

import com.sright.bcard.common.biz.manager.*;
import com.sright.bcard.common.service.share.dto.common.CheckResultDTO;
import com.sright.bcard.common.service.share.utils.JedisUtil;
import com.sright.common.response.SrightResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.LinkedList;
import java.util.List;

@RestController
@RequestMapping("/jedis")
@Slf4j
public class JedisController {

    @Autowired
    private JedisUtil jedisUtil;

    @Autowired
    private DingTalkManager dingTalkManager;

    @Autowired
    private WxappManager wxappManager;

    @Autowired
    private ContentCheckManager contentCheckManager;

    /**
     * 注入发送邮件的接口
     */
    @Autowired
    private IMailManager mailService;

    @Value("${aliyun.miniapp.oss.isEnable}")
    private String isEnable;

    @GetMapping("/test")
    public SrightResponse getTest(@RequestParam(value = "content") String content) {
        Integer userId = 1651;
        String path = "pages/card/main?t=3&cardId=&userId=" + userId + "&lang=zh&u=1";
        try {
            wxappManager.createQrCode(path);
        } catch (Exception e) {
            e.printStackTrace();
        }
//        CheckResultDTO result = contentCheckManager.singleImageCheck(content);
        return SrightResponse.defaultSuccess();
    }

    @GetMapping("/lock")
    public SrightResponse getLock() {
        Boolean lock = jedisUtil.getLock("lock", 100000L);
        if(lock) {
            log.info("获取锁成功");
        } else {
            jedisUtil.releaseLock("lock");
            log.info("释放锁成功");
        }
        return SrightResponse.defaultSuccess(lock);
    }
}
